package com.bupt.Algorithm;

import com.bupt.utils.GenerateIDUtils;
import lombok.Data;

import java.util.List;

public abstract class TraverseAlgorithm {
    //邻接矩阵
    @Data
    public static final class Adjacency {
        protected String key = GenerateIDUtils.generateIdStr();
        protected int index;
        protected double weight = 0;
        protected Adjacency nextAdjacency;
        protected boolean inStack = false;

        public Adjacency andIndex(int index) {
            this.index = index;
            return this;
        }

        public Adjacency andWeight(double weight) {
            this.weight = weight;
            return this;
        }

        //添加邻接表，头插入
        public Adjacency andNextAdjacency(Adjacency nextAdjacency) {
            if (this.nextAdjacency == null) {
                this.nextAdjacency = nextAdjacency;
                return this;
            }
            nextAdjacency.andNextAdjacency(this.nextAdjacency);
            this.nextAdjacency = nextAdjacency;
            return this;
        }

        public Adjacency andInStack(boolean inStack) {
            this.inStack = inStack;
            return this;
        }

    }

    public static Adjacency createAdjacency() {
        return new Adjacency();
    }

    public abstract List<List<Integer>> search(List<Adjacency> adjacencyList, int origin, int destination);
}